import time
from flask import Blueprint,Response, request
import numpy as np
import cv2


bp = Blueprint("river",__name__,url_prefix="/river")

@bp.route('/test')
def get_test():
    return "test"

import riversr.utils as utils
# example: http://127.0.0.1:5555/river/height/617.22
@bp.route('/height/<height>')
def get_speed(height):
    t = utils.RiverSpeed(float(height))
    area = t.area
    speed = t.speed
    runoff = t.runoff
    # return "高程为"+height+",面积为"+str(area)+",流速为"+str(speed)+",流量为"+str(runoff)
    # json
    return  {
        "height":height,
        "area":area,
        "speed":speed,
        "runoff":runoff
    }

import pandas as pd
@bp.route('/speed/<speed>') # example: http://localhost:5555/river/speed/2.4889
def get_riverInfo(speed):
    speed = float(speed)
    if speed > 2.62 :
        speed = 2.62
    df = pd.read_csv('assets/river.csv')
    df = df[round(df['speed'],2) == round(speed,2)]
    result = df.iloc[0].to_dict()
    
    return result